//点击增加
$('#add').click(function () {
    $(window.parent.document).find('body').css({'overflow': 'hidden'});
    $(window.parent.document).find("#news").attr('src', 'edit.jsp?act=add').show();
});

//点击编辑
$('#edit').click(function () {
    var checkbox = $('input[type=checkbox]').is(':checked');
    var checked = $("input[name='id']:checked");
    if (checked.length > 1) {
        prompt("一次只能编辑一篇文章！", false);
        return false;
    } else if (checkbox) {
        $(window.parent.document).find('body').css({'overflow': 'hidden'});
        $(window.parent.document).find("#news").attr('src', 'edit.jsp?act=edit&id=' + checked.val()).show();
    } else {
        prompt("请选择要操作的文章！", false);
        return false;
    }
});

//删除
$('#del').click(function () {
    var checkbox = $('input[type=checkbox]').is(':checked');
    var arr = new Array();
    //var checked = $("input[name='id']:checked");
    if (!checkbox) {
        prompt("请选择要删除的文章！", false);
        return false;
    } else {
        $("input[type='checkbox']:checked").each(function (k, v) {
            arr.push(v["value"]);
        })
        $(window.parent.document).find("#sele").attr("str", "/my/delete").show();
        $(window.parent.document).find("#confirm").attr("val", arr);
        //确认删除
        return false;
    }
});

//弹框
function prompt(text, judge) {
    if (judge) {
        $(window.parent.document).find('#alert img').attr("src", "../img/dui.png");
    }
    $(window.parent.document).find('#alert').show();
    $(window.parent.document).find('#prompt').text(text);
    $(window.parent.document).find('body').css({'overflow': 'hidden'});
    $(window.parent.document).find('#alert div b').click(function () {
    $(window.parent.document).find('#alert').hide();
    $(window.parent.document).find('body').css({'overflow': 'auto'});
    });
}
//下一页
var pag = $('#page').find("b").last().text();//总页数
var now = $('#page').find("b").first().text();
$('#next').click(function () {
    if (now < pag) {
        now++;
        $(this).attr("href", "dynamic.jsp?curpage=" + now + "");
    } else {
        $(this).attr("href", "#");
    }
})
//上一页
$('#pervious').click(function () {
    if (now > 1) {
        now--;
        $(this).attr("href", "dynamic.jsp?curpage=" + now + "");
    } else {
        $(this).attr("href", "#");
    }
})
//首页
$('#first').click(function () {
    $(this).attr("href", "dynamic.jsp?curpage=1");
})
//尾页
$('#last').click(function () {
    $(this).attr("href", "dynamic.jsp?curpage=" + pag + "");
})
//跳转
$('#ack').click(function () {
    var jump = $('#jump').val();
    if (0 < jump && jump < pag) {
        pag = jump;
        document.location="dynamic.jsp?curpage=" + pag + "";
    }
})
